package com.example.li.controller;

import com.example.li.model.User;
import com.example.li.service.UserService;
import com.example.li.util.ResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    //登录
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public ResultDTO login(@RequestBody User user) {
        return userService.login(user);
    }

    //    注册
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public ResultDTO register(@RequestBody User user) {
        return userService.insert(user);
    }

    //    修改
    @RequestMapping(value = "/updateUser", method = RequestMethod.POST)
    public ResultDTO update(@RequestBody User user) {
        return userService.update(user);
    }

    //    展示列表
    @RequestMapping(value = "/getUserList", method = RequestMethod.POST)
    public ResultDTO getUserList(@RequestBody User user) {
        return new ResultDTO().success(userService.getUserList(user));
    }

    //    删除
    @RequestMapping(value = "/deleteUser", method = RequestMethod.POST)
    public ResultDTO deleteUser(@RequestBody User user) {
        return userService.deleteUser(user);
    }
    //    通过id显示用户信息
    @RequestMapping(value = "/showUser",method = RequestMethod.POST)
    public ResultDTO showUser(@RequestBody User user){
        return userService.showUser(user);
    }
}